package scalapackage.testcurrying

/**
  * Created by Germmy on 2018/4/10.
  */
class TestCurrying {

}

object TestCurrying{
  def main(args: Array[String]) {
    //最简单的柯里化
    def currying(x:Int)(y:Int)=x*y
    def curry=currying(3) _
    val rest1=curry(4)
//    curry(4)(5) //科里化后，不能再传2个参数了
//    println(rest1)

    //隐式转换
    def m2(x:Int)(implicit y:Int=5)=x*y
    implicit  val abc=100
    val rest2=m2(4)
    val rest3=m2(4)(6)
//    println(rest2)
//    println(rest3)

    //foldLeft本质上也是一种颗粒化
    val arr=Array(("scala",1),("scala",2),("scala",3))
    val res4=arr.foldLeft(0)(_ + _._2)
//    println(res4)
    def m3(x:Int)=(y:Int)=>x*y
    def curry2=m3(4)
    val res5=curry2(5)
    println(res5)
  }
}
